package com.xmh.demo.entity;

import java.util.Date;
import java.math.BigDecimal;
import java.util.Map;
import java.util.HashMap;
import com.alibaba.fastjson.JSONObject;
import java.sql.Timestamp;
import lombok.Data;
import java.io.Serializable;

@Data
public class UserEntity implements Serializable {

	/**
	 * 版本号
	 * 表备注：
	 */
	private static final long serialVersionUID = 1571871611989228207L;

	/**
	 *
	 */
	private String password;

	/**
	 *
	 */
	private Integer id;

	/**
	 *
	 */
	private String username;

	/**
	 *
	 */
	private String nickname;

	/**
	 *
	 */
	private Boolean userEnabled;

	/**
	 *
	 */
	private Date createDate;

	/**
	 *
	 */
	private Date updateDate;

	@SuppressWarnings("unchecked")
	public UserEntity(String json) {
		this(JSONObject.parseObject(json, Map.class));
	}

	public UserEntity() {}

	public UserEntity(Map<String, Object> map) {
		if (map == null || map.isEmpty()) {
			return;
		}

		password = (String) map.get("password");

		if (map.get("id") != null) {
			id = Integer.valueOf(String.valueOf(map.get("id")));
		}

		username = (String) map.get("username");

		nickname = (String) map.get("nickname");

		if (map.get("userEnabled") != null) {
			userEnabled = Boolean.valueOf(String.valueOf(map.get("userEnabled")));
		}

		Object createDateobj = map.get("createDate");
		if (createDateobj != null) {
			if (createDateobj instanceof Date) {
				createDate = (Date) createDateobj;
			} else {
				createDate = new Date((long) createDateobj);
			}
		}

		Object updateDateobj = map.get("updateDate");
		if (updateDateobj != null) {
			if (updateDateobj instanceof Date) {
				updateDate = (Date) updateDateobj;
			} else {
				updateDate = new Date((long) updateDateobj);
			}
		}

	}

    public Map toMap() {
        Map map = new HashMap();
        map.put("password", password);
        map.put("id", id);
        map.put("username", username);
        map.put("nickname", nickname);
        map.put("userEnabled", userEnabled);
        map.put("createDate", createDate);
        map.put("updateDate", updateDate);
        return map;
    }


}